<?xml version="1.0" encoding="utf-8"?>
<Content xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:blueonionsoftware-com:bloget:runtime:data">
  <text>As a convenience for hosting Forms as children in unmanaged windows, we created the ManagedRootForm class which is derived from System.Windows.Forms.Form.  As I wanted to implement the Dispose pattern on this form, in preparation for some future generalizations, I dug into what aspects of the pattern are applicable in this scenario.



&lt;code&gt;    public class ManagedRootForm : Form /* already IDisposable via Control */
    {
        public ManagedRootForm()
        {
        }

        #region IDisposable Pattern
        //
        //Finalizer unnecessary: Control (via System.ComponentModel,Component) already has a finalizer that will
        //result in your Dispose(bool) being called
        //
        //~ManagedRootForm()
        //{
        //    Dispose(false);
        //}

        //
        // No need to replace Dispose: Control (via System.ComponentModel,Component) already implements this 
        // correctly, and your Dispose(bool) method will be called
        //
        //new void Dispose()
        //{
        //    Dispose(true);
        //    GC.SuppressFinalize(this);
        //}

        private bool _isDisposed = false;
        protected override void Dispose(bool managed)
        {
            if (_isDisposed)
                return;
            _isDisposed = true;

            // null out events
           myEventThatSomeoneSubscribedTo = null;

            // dispose of managed resources here, if any...
            if (managed)
            {
            }

            base.Dispose(managed);
        }

        #endregion IDisposable Pattern
    }&lt;/code&gt;
</text>
  <last_update>2007-10-04T00:52:37.2140806Z</last_update>
  <source_title />
  <source_link />
  <comments />
  <references />
  <attachments />
</Content>